
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0803
 * @Author : WangRuoyu 
 * @Date : 2023/9/16 15:55
 */

#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<pair<int, int>> p;
    for (int i = 0; i < n; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);
        p.push_back({l, r});
    }

    sort(p.begin(), p.end());

    int res = 0;
    int l = -0x3f3f3f3f;
    int r = -0x3f3f3f3f;

    for (int i = 0; i < p.size(); ++i) {
        if (p[i].first > r) {
            res++;
            l = p[i].first;
            r = p[i].second;
        } else {
            r = max(r, p[i].second);
        }
    }

    printf("%d", res);

    return 0;
}